import './index.scss'
import { newChooseGoodsPoints } from '../../api/shoppingMall/chooseGoods'

export default {
  name: 'choose-goods-points',
  props: {
    isGetChooseData: { // 是否开始返回数据
      type: Boolean,
      default: false
    },
    clickNum: {
      type: Number,
      default: 1
    },
    isGetType: {
      type:String,
      default:''
    },
    channel:{
      type:Array,
      default:[]
    }
  },
  watch: {
    clickNum(val) {
      this.getGoodsTabel()
      console.log('val', val)
    },
    isGetChooseData() {
      if (!this.currentChooseGoods.length) {
        this.$message.error('请选择商品')
        return
      }
      this.$emit('chooseGoodsFun', {
        data: this.currentChooseGoods
      })
    }
  },
  data() {
    return {
      chooseParams: {
        // 积分商城场景
        campaignScene: '',
        channel: [2],
        pageNum: 1,
        pageSize: 40
      },
      list: [
        {
          id: 10,
          goodsName: '液体颊彩1',
          subTitle: '这里是商品描述',
          price: '1.00',
          // mainImage: '../../assets/commons/img_8.jpg',
          comeNum: 0,
          viewNum: 0,
          skuNum: 100,
          salesVolume: 10,
          gtmTime: '2019-08-02 15:30:30'
        },
        {
          id: 11,
          goodsName: '液体颊彩2',
          subTitle: '这里是商品描述',
          price: '4.00',
          // mainImage: '../../assets/commons/img_9.jpg',
          comeNum: 32,
          viewNum: 13,
          skuNum: 120,
          salesVolume: 10,
          gtmTime: '2019-08-02 15:36:30'
        }
      ],
      option: {
        isPagination: true,
        isMenu: false,
        height: 350,
        paginationTotal: 40,
        paginationCurrent: 1,
        paginationSize: 40,
        isSelection: true,
        highlightCurrentRow: true,
        column: [
          {
            label: '活动名称',
            prop: 'name',
            slotName: 'name',
            menuWidth: '100%',
            menuAlign: 'center'
          }
        ]
      },
      currentChooseGoods: []// 当前选择的
    }
  },
  created() {
    // this.getGoodsTabel()
  },
  mounted() {
    this.chooseParams.campaignScene = this.isGetType
    this.chooseParams.channel = this.channel
    this.getGoodsTabel()
  },
  methods: {
    // 获取商品信息
    getGoodsTabel() {
      newChooseGoodsPoints(this.chooseParams).then(res => {
        this.list = res.records
        this.option.paginationTotal = res.total
        console.log(res)
      })
    },
    // 选中信息
    selectionChange(ev) {
      console.log('ev',ev)
      ev.forEach(item => {
        item.goodsId = item.campaignVO.goodsId
      })
      this.currentChooseGoods = ev
      console.log('this.currentChooseGoods',this.currentChooseGoods)
    },
    // 分页
    currentChange(ev) {
      console.log('11111111')
      this.chooseParams.pageNum = ev.current
      this.getGoodsTabel()
      console.log('chooseParams',this.chooseParams)
    }
  }
}
